'- from Paulo Silva, GPL license, december '10
setdisplay(512,256,32,1):paper(0x7f7f7f):ink(0):pen(0):cls
'-- define cluster
dim clust[8,8]:a$="00,06,08,14,02,12,04,10,08,14,00,06,04,10,02,12"
for y2=0 to 3:for x2=0 to 3:lc=(y2*4)+x2
  clust[x2,y2]=val(mid$(a$,(lc*3)+1,2)):next:next
captool$="fswebcam"
while 0=0
  if captool$="vgrabbj" then
    setcaption("dummy")
    shell("vgrabbj -d /dev/video0 -F 4 -f _1.jpg")
    setcaption("del")
    shell("rm _1.jpg")
    setcaption("webcam")
    shell("vgrabbj -d /dev/video0 -F 4 -f _1.jpg")
    end if
  if captool$="fswebcam" then
    setcaption("del")
    shell("rm _1.jpg")
    setcaption("webcam")
    shell("fswebcam -d /dev/video0 _1.jpg")
    end if
  setcaption("imagemagick")
  shell("convert _1.jpg -resize 512x256\\! _2.jpg")  '- shell("convert _tmpr1.jpg -resize 512x256\\! -level 0,80%,1 _tmpr2.jpg")
  setcaption("del")
  shell("rm _1.jpg")
  setcaption("load")
  loadimage("_2.jpg",1):pasteicon(0,0,1)
  setcaption("del")
  shell("rm _2.jpg")
  setcaption("conv")
  '---
for y=0 to 255:for x1=0 to 63
  btv=0
  for x2=0 to 7
    x=(x1*8)+x2
    ind=point(x,y)
    b=ind mod 256:ind=int(ind/256)
    g=ind mod 256:ind=int(ind/256)
    r=ind mod 256
    w=int(((b*11)+(r*30)+(g*59))/100)
    patgf=(((clust[x mod 4,y mod 4]+1)*255)/16)
    wpat=0:if w>patgf then:wpat=1:end if
    btv=btv*2:btv=btv+wpat
    ink(0):if wpat<>0 then:ink(0xFFFFFF):end if:dot(x,y)
    next
  next:next

'- saves the image
grab (1,0,0,512,256):saveimage("_.bmp",1):shell ("convert _.bmp _.png && rm _.bmp")
wend


